#include <bits/stdc++.h>
using namespace std;
const int maxn = 100+10;
bool en[maxn*2];
int in[maxn][maxn], out[maxn][maxn];
int tok[maxn];
int P, T, F, kase = 0;
void init(){
    memset(in, 0, sizeof(in));
    memset(out, 0, sizeof(out));
    memset(tok, 0, sizeof(tok));
    memset(en, false, sizeof(en));
}

bool check(int t){
    for (int p = 1; p <= P; ++p) {
        if(in[t][p]){
            if(in[t][p] > tok[p]) return false;
        }
    }
    return true;
}

void fire(int t){
    for (int p = 1; p <= P; ++p) {
        if(out[p][t]) tok[p] -= out[p][t];
        if(out[t][p]) tok[p] += out[t][p];
    }
}

int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    string line;
    while(getline(cin, line) && line[0]!='0') {
        stringstream ss(line); ss >> P;
        init();
        cout << "Case " << ++kase << ": ";
        ss.clear(); getline(cin, line); ss.str(line);
        for (int i = 1; i <= P; ++i) {
            ss >> tok[i];
        }
        ss.clear(); getline(cin, line); ss.str(line);
        ss >> T;
        int cntEn = 0;
        for (int t = 101; t <= T + 100; ++t) {
            ss.clear(); getline(cin, line); ss.str(line);
            int p;
            while (ss >> p && p != 0) {
                if (p > 0) {
                    ++out[t][p];
                    ++in[p][t];
                } else {
                    p = -p;
                    ++in[t][p];
                    ++out[p][t];
                }
            }
            if(check(t)) {en[t] = true; ++cntEn;}
        }
        ss.clear(); getline(cin, line); ss.str(line);
        ss >> F;

            bool dead = false;
            int cntf = 0;
        for (int i = 1; i <= F; ++i) {
            if(cntEn){
                ++cntf;
                int t;
                for (t = 101; t <= T+100; ++t) {
                    if(en[t]) break;
                }
                fire(t);

                for (int p = 1; p <= P; ++p) {
                    // check in
                    if(out[p][t]) {
                        for (int t2 = 101; t2 < T+101; ++t2) {
                            if(out[p][t2] && en[t2])
                                if(tok[p] < in[t2][p]) {en[t] = false; --cntEn;}
                        }
                    }
                    //check out
                    if(out[t][p]){
                        for (int t2 = 101; t2 <= T+101; ++t2) {
                            if(out[p][t2] && !en[t2])
                                if(check(t2)) {en[t2] = true; ++cntEn;}
                        }
                    }
                }

            }else {dead = true; break;}
        }
        if(!dead)cout << "still live after " << F << " transitions\n";
        else cout << "dead after " << cntf << " transitions\n";
        cout << "Places with tokens:";
        for (int i = 1; i <= P; ++i) {
            if(tok[i]) cout << " " << i << " (" << tok[i] << ")";
        }
        cout << "\n\n";
    }
    return 0;
}